<template>
  <t-dialog :header="dialogInfo.header" :visible.sync="dialogInfo.visible" :onClose="closeDialog"
    :closeOnOverlayClick="false" :confirmBtn="null" width="90%" top="5%">
    <t-form labelWidth="140px" >
      <t-row style="align-items: stretch;padding: 10px">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="人员信息">
            <t-table
              rowKey="index"
              size="small"
              :data="data"
              :columns="columns"
              hover
              :hideSortTips="true"
            >
              <template #sex="{ row }">
                {{ row.sex | filterByDict(dictTypes.sys_user_sex)  }}
              </template>
              <template #profTitId="{ row }">
                {{ row.profTitId | filterByTree(profTitOptions) }}
              </template>
              <template #profTit="{ row }">
                {{ row.profTit | filterByDict(dictTypes.prof_tit)  }}
              </template>
              <template #degree="{ row }">
                {{ row.degree | filterByDict(dictTypes.degree) }}
              </template>
              <template #education="{ row }">
                {{ row.education | filterByDict(dictTypes.education) }}
              </template>
              <template #isInnerCompany="{ row }">
                {{row.isInnerCompany==1?"是":"否"}}
              </template>
              <template #sbjTitle="{ row }">
                {{row.sbjTitle==1?"是":"否"}}
              </template>
              <template #op="{ row }">
                <!--                <t-button size="small" variant="text" class="t-button-link">-->
                <!--                  <t-icon name="info-circle" slot="icon"/>-->
                <!--                  详情-->
                <!--                </t-button>-->
                <t-button size="small" @click="edit(row)" variant="text" class="t-button-link">
                  <t-icon name="edit-1" slot="icon"/>
                  编辑
                </t-button>
                <t-button
                  theme="danger"
                  @click="deleteItem(row)"
                  size="small"
                  variant="text" class="t-button-link">
                  <t-icon name="delete" slot="icon"/>
                  删除
                </t-button>
              </template>
            </t-table>
          </t-card>
        </t-col>
      </t-row>
    </t-form>
  </t-dialog>
</template>

<script>

import {getFiles} from "@/api/common";
import {getDictList} from "@/api/system/dict/data";

export default {
  name: "people-info",
  dicts:["formulate_type","bzh_approve_type","approve_status","local_standard_status","standard_category"],
  components: {
  },
  props: {
    dialogInfo: {
      type: Object,
      default() {
        return {
          id: "",
          header: "",
          visible: true
        }
      }
    },
  },
  data() {
    return {
      dictTypes: {},
      columns:[
        {
          colKey: "year",
          title: "投入时间",
          align: "center",
          width: 220
        },
        {
          colKey: "name",
          title: "姓名",
          align: "center",
          width: 220
        },
        {
          colKey: "idCard",
          title: "身份证号",
          align: "center",
          width: 220
        },
        {
          colKey: "sex",
          title: "性别",
          align: "center",
          width: 220
        },
        {
          colKey: "birthDate",
          title: "出生年月",
          align: "center",
          width: 220
        },
        {
          colKey: "profTitId",
          title: "职称",
          align: "center",
          width: 220
        },
        {
          colKey: "profTit",
          title: "职称等级",
          align: "center",
          width: 220
        },
        {
          colKey: "duty",
          title: "职务",
          align: "center",
          width: 220
        },
        {
          colKey: "company",
          title: "所在单位名称",
          align: "center",
          width: 220
        },
        {
          colKey: "isInnerCompany",
          title: "是否为内部",
          align: "center",
          width: 220
        },
        {
          colKey: "degree",
          title: "学位",
          align: "center",
          width: 220
        },
        {
          colKey: "education",
          title: "学历",
          align: "center",
          width: 220
        },
        {
          colKey: "sbjTitle",
          title: "是否获奖省部级人才称号",
          align: "center",
          width: 220
        },
        {
          colKey: "note",
          title: "备注",
          align: "center",
          width: 220
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120,
          fixed: 'right'
        },
      ],
      value:"1",
      deptMenuOptions:[],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },
        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
      projectFileData: [
        {
          id: 1,
          c1: "登记附件",
          c2: "否",
          moduleKey: "projectLXGW",
          fileIds: [],
          fileLists: [],
        },
      ],
      tabValue:"1",
      profTitOptions:[],
      data:[]
    }
  },

  async mounted() {
    await this.getDataTypes()
    await this.getProfTitTreeSelect()
    await this.getDetail()
    await this.getDeptTreeSelect()
  },
  methods: {
    edit(row){
      this.$emit("edit",row)
    },
    deleteItem(row){
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除？`,
        theme: "warning",
        onConfirm: ({e}) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.kjpt.people.delete(row.id).then(
            (res) => {
              this.getDetail();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        }
      });
    },
    getDataTypes() {
      return getDictList(["project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "education", "duty", "platform_type", "expect_result_type"]).then(response => {
        this.dictTypes = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getProfTitTreeSelect() {
      return this.$api.system.profTit.treeselect().then(response => {
        this.profTitOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeptTreeSelect(){
      return this.$api.system.dept.treeSelectAllIn().then(response=>{
        this.deptMenuOptions = response.data
      }).catch(e=>{
        this.$message.error(e.toString())
      })
    },
    closeDialog() {
      this.$emit("closeBzhDialog", false);
      this.dialogInfo.visible = false
    },
   getDetail(){
      this.$api.kjpt.people.getByPlatformId(this.dialogInfo.id).then(response=>{
        this.data = response.data
        this.data.forEach((item,index)=>{
          if (!item.note){
            this.data[index].note = "无"
          }
        })
      })
    },
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 14px;
}
.step-card{
  margin: 10px;
}
.content_style{
  font-size: 12pt;
  font-family: 宋体;
  line-height: 1.5;
}
</style>
